//
//  ViewController.m
//  HIGHT
//
//  Created by 夜空 on 2017/4/18.
//  Copyright © 2017年 夜空. All rights reserved.
//
#import "sys/utsname.h"
#define UISCREEN_HEIGHT ([[UIScreen mainScreen]bounds].size.height)
#define UISCREEN_WIDTH ([[UIScreen mainScreen]bounds].size.width)

#import "ViewController.h"
#import "Masonry/Masonry.h"
#import "AFNetworking/AFNetworking.h"
#import "HAViewController.h"
@interface ViewController ()
{
    AFNetworkReachabilityManager *mgr;

}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@",[self getDeviceName]);
    if (UISCREEN_HEIGHT==812) {
        NSLog(@"iPhoneX");
        self.view.backgroundColor=[UIColor whiteColor];
    }else{
        self.view.backgroundColor=[UIColor lightGrayColor];
        NSLog(@"iPhone~~~~~~~~");
    }
    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, onNotifyCallback, CFSTR("com.apple.system.config.network_change"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
    
    
    
    
    
    
    
    
    
    
   
    
    [self subview];
    
    
    mgr = [AFNetworkReachabilityManager sharedManager];
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态发生改变的时候调用这个block
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");
                //                [self showText:@"wifi!"];
                [[NSUserDefaults standardUserDefaults] setObject:@"wifi" forKey:@"network"];
                break;
                
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"自带网络");
                //                [self show Text:@"3G|4G网络!"];
                [[NSUserDefaults standardUserDefaults] setObject:@"3g" forKey:@"network"];
                
                break;
                
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"没有网络");
                [[NSUserDefaults standardUserDefaults] setObject:@"without" forKey:@"network"];
                
                break;
                
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络!");
                [[NSUserDefaults standardUserDefaults] setObject:@"unknown" forKey:@"network"];
                
                break;
            default:
                break;
        }    }];
    // 开始监控
    [mgr startMonitoring];
    
    
    
    
    
    
    
    
    
    
    
    
    
    self.view.userInteractionEnabled = YES;
    UIScrollView *  _bigscrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 24, 320,568)];
    _bigscrollV.showsHorizontalScrollIndicator=NO;
    [_bigscrollV setBounces:NO];
    [_bigscrollV setContentSize:CGSizeMake(320, 2000)];
    _bigscrollV.userInteractionEnabled = YES;
    [self.view addSubview:_bigscrollV];

    
    
    
    UILabel * label=[[UILabel alloc] init];
    label.text=@"吉尼斯：";
    label.font=[UIFont systemFontOfSize:11];
    [_bigscrollV addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_bigscrollV.mas_top).offset(20);
        make.left.mas_equalTo(10);
//        make.width.mas_equalTo(50);
//        make.height.mas_equalTo(12*kScreenHeightRatio);
    }];
    UIButton * nextbtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [nextbtn setTitle:@"下一页" forState:UIControlStateNormal];
    [nextbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    nextbtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    nextbtn.titleLabel.font=[UIFont systemFontOfSize:11];
    [nextbtn addTarget:self action:@selector(nextbtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextbtn];
    
    [nextbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(label.mas_bottom).offset(100);
        make.left.mas_equalTo(10);
        make.width.mas_equalTo(200);
        //        make.height.mas_equalTo(12*kScreenHeightRatio);
    }];
    
    
    
    UILabel * hah=[[UILabel alloc] init];
    hah.text=@"啦啦队队长说不出来你的爱着他那时候你们才好。，啦啦啦55555图来了句啦啦啦啦噜啦啦啦啦噜啦我 my做了条件图姆推荐他具体啦噜图来了句吐吐了嗯咯模样赵总微信莫其妙";
    hah.font=[UIFont systemFontOfSize:13];
    hah.numberOfLines=0;
    [_bigscrollV addSubview:hah];
    [hah mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_bigscrollV.mas_top).offset(20);
        make.left.mas_equalTo(label.mas_right).offset(20);
        make.width.mas_equalTo(220);
        //        make.height.mas_equalTo(12*kScreenHeightRatio);
    }];
    CGRect rect = [hah.text boundingRectWithSize:CGSizeMake(200, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: label.font} context:nil];
    [_bigscrollV setContentSize:CGSizeMake(320, 20+rect.size.height)];

    
    
//     Do any additional setup after loading the view, typically from a nib.
}
static void onNotifyCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
    NSString* notifyName = (__bridge NSString *) name;
    if ([notifyName isEqualToString:@"com.apple.system.config.network_change"]) {
        
        
        
        
    } else {
        NSLog(@"intercepted %@", notifyName);
    }
}
-(void)nextbtn:(UIButton *)sender{
    
//    常見的轉換類型（type）：
//    kCATransitionFade               //淡出
//    kCATransitionMoveIn          //覆盖原图
//    kCATransitionPush               //推出
//    kCATransitionReveal          //底部显出来
//    SubType:
//    kCATransitionFromRight
//    kCATransitionFromLeft    // 默认值
//    kCATransitionFromTop
//    kCATransitionFromBottom
//    设置其他动画类型的方法(type):
//    pageCurl   向上翻一页。
//    pageUnCurl 向下翻一页
//    rippleEffect 滴水效果
//    suckEffect 收缩效果，如一块布被抽走
//    cube 立方体效果
//    oglFlip 上下翻转效果
    
    
    
    CATransition *animation = [CATransition animation];
    animation.duration = 1.0;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.type = @"oglFlip";
    animation.subtype = kCATransitionFromLeft;
    [self.view.window.layer addAnimation:animation forKey:nil];
    
    
    
    HAViewController * ha=[[HAViewController alloc] init];
    UINavigationController * nav=[[UINavigationController alloc] initWithRootViewController:ha];

//    [self.navigationController pushViewController:nav animated:YES];
    [self presentViewController:nav animated:NO completion:nil];

}
-(void)subview{
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSDictionary * dic=@{@"order":@"login",@"name":@"admin",@"pwd":@"123lzkjadmin"};
    [manager GET:@"http://218.61.125.164:8051/Program/UserModule.ashx" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary * dic=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@",[dic objectForKey:@"msg"]);
        NSLog(@"%@",dic);

        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        
    }];

//    [manager POST:@"http://218.61.125.164:8051/Service1.svc?wsdl=Behavior" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        
//    }];
//


}

#pragma 限制字数
//- (void)textFieldChange{
//    
//    NSString *toBeString = self.textfiled.text;
//    NSString *lang = self.textfiled.textInputMode.primaryLanguage;
//    
//    if([lang isEqualToString:@"zh-Hans"]){ //简体中文输入，包括简体拼音，健体五笔 简体手写
//        
//        UITextRange *selectedRange = [self.textfiled markedTextRange];
//        
//        UITextPosition *position = [self.textfiled positionFromPosition:selectedRange.start offset:0];
//        
//        NSLog(@"%@",selectedRange);
//        NSLog(@"%@",position);
//        
//        if (!position){//非高亮
//            if (toBeString.length > 15) {
//                
//                UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"标题长度不能超过15位" preferredStyle:UIAlertControllerStyleAlert];
//                UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
//                [alert addAction:action];
//                [self presentViewController:alert animated:YES completion:nil];
//                self.textfiled.text = [toBeString substringToIndex:15];
//                [self.labelNum setText:[NSString stringWithFormat:@"15/15"]];
//                CGSize size = [MyManager sharedManager:[NSString stringWithFormat:@"15/15"] AndFontSize:14];
//                self.labelNum.frame=CGRectMake(UISCREEN_WIDTH-size.width-20*kScreenWidthRatio, 0, size.width, 44*kScreenHeightRatio);
//            }
//            else{
//                [self.labelNum setText:[NSString stringWithFormat:@"%lu/15",self.textfiled.text.length]];
//                CGSize size = [MyManager sharedManager:[NSString stringWithFormat:@"%lu/15",self.textfiled.text.length] AndFontSize:14];
//                self.labelNum.frame=CGRectMake(UISCREEN_WIDTH-size.width-20*kScreenWidthRatio, 0, size.width, 44*kScreenHeightRatio);
//                
//            }
//            
//        }
//        
//    }else{//中文输入法以外
//        
//        if (toBeString.length > 15) {
//            
//            
//            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"标题长度不能超过15位" preferredStyle:UIAlertControllerStyleAlert];
//            UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
//            [alert addAction:action];
//            [self presentViewController:alert animated:YES completion:nil];
//            self.textfiled.text = [toBeString substringToIndex:15];
//            [self.labelNum setText:[NSString stringWithFormat:@"15/15"]];
//            CGSize size = [MyManager sharedManager:[NSString stringWithFormat:@"15/15"] AndFontSize:14];
//            self.labelNum.frame=CGRectMake(UISCREEN_WIDTH-size.width-20*kScreenWidthRatio, 0, size.width, 44*kScreenHeightRatio);
//        }
//        else
//        {
//            [self.labelNum setText:[NSString stringWithFormat:@"%lu/15",self.textfiled.text.length]];
//            CGSize size = [MyManager sharedManager:[NSString stringWithFormat:@"%lu/15",self.textfiled.text.length] AndFontSize:14];
//            self.labelNum.frame=CGRectMake(UISCREEN_WIDTH-size.width-20*kScreenWidthRatio, 0, size.width, 44*kScreenHeightRatio);
//            
//        }
//        
//    }
//    
//}



// 获取设备型号然后手动转化为对应名称
- (NSString *)getDeviceName
{
    // 需要#import "sys/utsname.h"
//
#warning 题主呕心沥血总结！！最全面！亲测！全网独此一份！！
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    if ([deviceString isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([deviceString isEqualToString:@"iPhone3,2"])    return @"iPhone 4";
    if ([deviceString isEqualToString:@"iPhone3,3"])    return @"iPhone 4";
    if ([deviceString isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([deviceString isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([deviceString isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
    if ([deviceString isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
    if ([deviceString isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (GSM+CDMA)";
    if ([deviceString isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
    if ([deviceString isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (GSM+CDMA)";
    if ([deviceString isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([deviceString isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    if ([deviceString isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([deviceString isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    if ([deviceString isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
    // 日行两款手机型号均为日本独占，可能使用索尼FeliCa支付方案而不是苹果支付
    if ([deviceString isEqualToString:@"iPhone9,1"])    return @"国行、日版、港行iPhone 7";
    if ([deviceString isEqualToString:@"iPhone9,2"])    return @"港行、国行iPhone 7 Plus";
    if ([deviceString isEqualToString:@"iPhone9,3"])    return @"美版、台版iPhone 7";
    if ([deviceString isEqualToString:@"iPhone9,4"])    return @"美版、台版iPhone 7 Plus";
    if ([deviceString isEqualToString:@"iPhone10,1"])   return @"国行(A1863)、日行(A1906)iPhone 8";
    if ([deviceString isEqualToString:@"iPhone10,4"])   return @"美版(Global/A1905)iPhone 8";
    if ([deviceString isEqualToString:@"iPhone10,2"])   return @"国行(A1864)、日行(A1898)iPhone 8 Plus";
    if ([deviceString isEqualToString:@"iPhone10,5"])   return @"美版(Global/A1897)iPhone 8 Plus";
    if ([deviceString isEqualToString:@"iPhone10,3"])   return @"国行(A1865)、日行(A1902)iPhone X";
    if ([deviceString isEqualToString:@"iPhone10,6"])   return @"美版(Global/A1901)iPhone X";
    
    
    
    return deviceString;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
